﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Maticsoft.Web
{
    public partial class ListMN : System.Web.UI.Page
    {
        
        BLL.studentInfo s = new BLL.studentInfo();
        DataSet ds;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["type"] != null)
                {
                    string type = Server.UrlDecode(Request.QueryString["type"].ToString());
                    //[sCount] ,[mCount] ,[jCount] ,[sScore] ,[mScore] ,[jScore] 
                    //type = "机关单位";
                    lblssum.Text = "20";
                    lblmsum.Text = "10";
                    lbljsum.Text = "20";
                    lblsfen.Text = "2";
                    lblmfen.Text = "2";
                    lbljfen.Text = "2";
                    Bind(type);
                    //BindAnswer(stuId);   
                }
            }
               
        }
        private void Bind(string type)
        {            
                Maticsoft.BLL.singleInfo sm = new BLL.singleInfo();
                ds = sm.GetList(" stutype='" + type + "' order by newid()", lblssum.Text);           
            this.DataList1.DataSource = ds;
            this.DataList1.DataBind();            
                Maticsoft.BLL.mostInfo mm = new BLL.mostInfo();
                ds = mm.GetList(" stutype='" + type + "' order by newid()", lblmsum.Text);            
            this.DataList2.DataSource = ds;
            this.DataList2.DataBind();            
                Maticsoft.BLL.judgeInfo jm = new BLL.judgeInfo();
                ds = jm.GetList(" stutype='" + type + "' order by newid()", lbljsum.Text);            
            this.DataList3.DataSource = ds;
            this.DataList3.DataBind();
        }

        //提交答案
        protected void btn_submit_Click(object sender, EventArgs e)
        {
           
                
                //保存时间
              

        }
        protected int[] timeload(string a)
        {
            int[] t = new int[3];
            t[0] = int.Parse(a.Split(':')[0]);
            t[1] = int.Parse(a.Split(':')[1]);
            t[2] = int.Parse(a.Split(':')[2]);
            return t;
        }
        private void SubmitQuestion()
        {
            Maticsoft.BLL.keyinfo km = new BLL.keyinfo();
            Maticsoft.Model.keyinfo k = null;

            //km.DeleteByWhere(" stuId=" + stuId + " and type = 1 ");//删除此学生的所有已提交单项选择答案
            foreach (DataListItem item in this.DataList1.Items)
            {
                //Label lbl_title = (Label)item.FindControl("lbl_title");
                Label lbl_singleId = (Label)item.FindControl("lbl_singleId");
                RadioButton rdoA = (RadioButton)item.FindControl("rdoA");
                RadioButton rdoB = (RadioButton)item.FindControl("rdoB");
                RadioButton rdoC = (RadioButton)item.FindControl("rdoC");
                RadioButton rdoD = (RadioButton)item.FindControl("rdoD");
                string key = ((HiddenField)item.FindControl("hfkey")).Value;
                Label l = (Label)item.FindControl("lblan");
                //string title = lbl_title.Text;
                string singleId = lbl_singleId.Text;//题目ID 

                string result = "";

                if (rdoA.Checked)
                {
                    result = "A";
                }
                if (rdoB.Checked)
                {
                    result = "B";
                }
                if (rdoC.Checked)
                {
                    result = "C";
                }
                if (rdoD.Checked)
                {
                    result = "D";
                }
                if (result != key)
                {
                    l.Text = "正确答案是：" + key;
                    l.ForeColor = System.Drawing.Color.Red;
                }
                else
                {
                    l.Text = "恭喜您答对了！";
                }

            }
            foreach (DataListItem item in this.DataList2.Items)
            {
                Label lbl_title = (Label)item.FindControl("lbl_title");
                Label lbl_mostId = (Label)item.FindControl("lbl_mostId");

                CheckBox cboA = (CheckBox)item.FindControl("cboA");
                CheckBox cboB = (CheckBox)item.FindControl("cboB");
                CheckBox cboC = (CheckBox)item.FindControl("cboC");
                CheckBox cboD = (CheckBox)item.FindControl("cboD");
                string key = ((HiddenField)item.FindControl("hfkey")).Value;
                Label l = (Label)item.FindControl("lblan");
                string title = lbl_title.Text;
                string mostId = lbl_mostId.Text;//题目ID 

                string result = "";

                if (cboA.Checked)
                {
                    result += "A";
                }
                if (cboB.Checked)
                {
                    result += "B";
                }
                if (cboC.Checked)
                {
                    result += "C";
                }
                if (cboD.Checked)
                {
                    result += "D";
                }
                if (result != key)
                {
                    l.Text = "正确答案是：" + key;
                    l.ForeColor = System.Drawing.Color.Red;
                }
                else
                {
                    l.Text = "恭喜您答对了！";
                }
               
            }
            foreach (DataListItem item in this.DataList3.Items)
            {
                Label lbl_title = (Label)item.FindControl("lbl_title");
                Label lbl_judgeId = (Label)item.FindControl("lbl_judgeId");
                RadioButton rdoYes = (RadioButton)item.FindControl("rdoYes");
                RadioButton rdoNo = (RadioButton)item.FindControl("rdoNo");
                string key = ((HiddenField)item.FindControl("hfkey")).Value;
                Label l = (Label)item.FindControl("lblan");
                string title = lbl_title.Text;
                string judgeId = lbl_judgeId.Text;//题目ID 

                string result = "";

                if (rdoYes.Checked)
                {
                    result = "正确";
                }
                if (rdoNo.Checked)
                {
                    result = "错误";
                }
                if (result != key)
                {
                    l.Text = "正确答案是：" + key;
                    l.ForeColor = System.Drawing.Color.Red;
                }
                else
                {
                    l.Text = "恭喜您答对了！";
                }
               
            }
        }       

        protected void btnOK_Click(object sender, EventArgs e)
        {
            SubmitQuestion();
            

        }
    }
}